#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPalette>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->rSlider, SIGNAL(valueChanged(int)),
            this, SLOT(on_slider_value_changed(int)));
    connect(ui->gSlider, SIGNAL(valueChanged(int)),
            this, SLOT(on_slider_value_changed(int)));
    connect(ui->bSlider, SIGNAL(valueChanged(int)),
            this, SLOT(on_slider_value_changed(int)));
    connect(ui->aSlider, SIGNAL(valueChanged(int)),
            this, SLOT(on_slider_value_changed(int)));
}

void MainWindow::on_slider_value_changed(int val){
    //Q_UNUSED 会告诉编译器：“我知道这个变量未被使用，这是有意为之，不要警告我。”
    Q_UNUSED(val);
    QColor color;
    int red = ui->rSlider->value();
    int green = ui->gSlider->value();
    int blue = ui->bSlider->value();
    int alpha = ui->aSlider->value();
    color.setRgb(red, green, blue, alpha);

    QPalette pal = ui->textEdit->palette();
    pal.setColor(QPalette::Base, color);
    ui->textEdit->setPalette(pal);
}

MainWindow::~MainWindow()
{
    delete ui;
}

